#include "stdafx.h"
#include <mapix.h>


namespace JMAPI {

	HRESULT GetPropList(LPMAPIPROP lpMAPIProp, ULONG ulFlags , LPSPropTagArray * lppPropTagArray)
	{
		HRESULT hRes = MAPI_E_NOT_ENOUGH_MEMORY;
		LPSPropTagArray lpPropTagArray = NULL;
		hRes = lpMAPIProp->GetPropList(ulFlags, &lpPropTagArray);
		if ( SUCCEEDED(hRes) && lpPropTagArray ) {
			DWORD cbSize = CbNewSPropTagArray( lpPropTagArray->cValues );
			*lppPropTagArray = (LPSPropTagArray)CoTaskMemAlloc( cbSize );
			if ( *lppPropTagArray ) {
				memcpy(*lppPropTagArray, lpPropTagArray, cbSize);
			} else {
				hRes = MAPI_E_NOT_ENOUGH_MEMORY;
			}
			MAPIFreeBuffer( (LPVOID*)&lpPropTagArray );
		}
		return hRes;
	}


	HRESULT GetProps(LPMAPIPROP lpMAPIProp, LPSPropTagArray lpPropTagArray , ULONG ulFlags , ULONG *lpcValues, LPSPropValue *lppPropArray)
	{
		HRESULT hRes = S_OK;
		ULONG cValues;
		LPSPropValue lpPropArray = NULL;
		hRes = lpMAPIProp->GetProps(lpPropTagArray, ulFlags, &cValues, &lpPropArray);
		hRes = AllocSPropValue(cValues, lpPropArray, lppPropArray);
		// 	*lppPropArray = lpPropArray;
		*lpcValues = cValues;
		// 	MAPIFreeBuffer(lpPropArray);
		return hRes;
	}
}